<template>
  <div class="container">
    <div class="con">
      <img src="/static/images/rank/top.png"  class="top">
      <!--排行榜-->
      <div class="rank">
        <img src="/static/images/rank/rank_bg.png" class="rank-img">
        <scroll-view class="rank-con" scroll-y>
          <div class="item" v-for="(item, index) in rankData" :key="item.openid" v-if="index < 5">
            <span class="no">{{item.rank}}</span>
            <span class="name">{{item.nickname}}</span>
            <span class="score">{{item.score}}</span>
          </div>
        </scroll-view>
      </div>
      <div class="myrank">
        <img src="/static/images/rank/share_bg.png" class="rank-img">
        <div class="rank-con" >
          <div class="item" >
            <span class="no">{{stuRank[0].rank}}</span>
            <span class="name">{{stuRank[0].nickname}}</span>
            <span class="score">{{stuRank[0].score}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    data () {
      return {
        rankData: [
        ],
        userData: {},
        stuRank: []
      }
    },
    beforeMount () {
      // fly
      this.$store.state.openid = wx.getStorageSync('openid')
      this.$fly.get(this.$store.state.URL + '/studygo/getRanking', {
        username: this.$store.state.openid
      })
        .then((response) => {
          console.log(response)
          this.rankData = response.data.data[0]
          this.stuRank = response.data.data[1]
        })
        .catch((error) => {
          console.log(error)
        })
    }
  }
</script>

<style>
  page {
    background-image: url();
  }

  .con{
    position: relative;
    font-size: 0;
    margin-top: 20rpx;
  }
  .top{
    position: relative;
    z-index: 2;
    width: 100%;
    height: 166rpx;
  }
  .rank{
    position: relative;
    width: 90%;
    height: 540rpx;
    margin: -14rpx auto 0;
  }
  .rank-img{
    position: absolute;
    width: 100%;
    height: 100%;
  }
  .rank-con{
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 50rpx 10rpx 14rpx 10rpx;
    overflow-y: auto;
  }
  .rank-con .item{
    width: 100%;
    height: 50rpx;
    line-height: 50rpx;
    text-align: center;
    border-bottom: 3px solid #000000;
    color: #000;
    font-size: 24rpx;
    display: flex;
  }
  .rank-con .item .no{
    flex: 0 0 25%;
    font-family: "华文楷体";
  }
  .rank-con .item .name{
    flex: 0 0 45%;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    font-family: "华文楷体";
  }
  .rank-con .item .score{
    flex: 0 0 30%;
    font-family: "华文楷体";
  }

  .myrank{
    position: relative;
    width: 90%;
    height: 120rpx;
    margin: -14rpx auto 0;
    font-family: "华文楷体";
  }

</style>
